import Vue from 'vue'
import Vuex from 'vuex'
import geo from './modules/geo'
import home from './modules/home'

Vue.use(Vuex)

const store = () => new Vuex.Store({
  modules: {
    geo,
    home
  },
  actions: {
    async nuxtServerInit({commit}, {req, app}) {
      // app是Vue实例
      let res = await app.$axios.get('/geo/getPosition')
      commit('geo/setPosition',res.data)
      const { data }=await app.$axios.get('geo/menu') || []
      commit('home/setMenu',data)
      const  { result } = await app.$axios.get('/search/hotPlace',{params:{city: '三亚'}})
      commit('home/setHotPlace',result)
    }
  }
})

export default store
